﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Brjnk.GpxExplorer.Workspace.Searching;

namespace Brjnk.GpxExplorer.UI
{
    /// <summary>
    /// Interaction logic for SearchTimeWindow.xaml
    /// </summary>
    public partial class SearchTimeWindow : Window, INotifyPropertyChanged
    {
        private SearchService service;

        public SearchTimeWindow(SearchService service)
        {
            InitializeComponent();
            this.service = service;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private DateTime time = DateTime.Now;

        public DateTime Time
        {
            get { return time; }
            set { time = value; OnPropertyChanged("Time"); }
        }

        private bool searchInGaps = true;

        public bool SearchInGaps
        {
            get { return searchInGaps; }
            set { searchInGaps = value; OnPropertyChanged("SearchInGaps"); }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (Validation.GetHasError(timeTxb))
                return;
            service.SearchedItems.Add(new SearchDateTimeRequest()
            {
                DateTime = this.Time,
                SearchInGaps = SearchInGaps,
                Color1 = colorPicker.Color,
                Color2 = Colors.Black
            });

            this.DialogResult = true;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}